﻿
namespace MVVMBasedDialogs.ViewModel
{
    using GalaSoft.MvvmLight;
    using System.Windows.Input;
    using GalaSoft.MvvmLight.Command;
    using GalaSoft.MvvmLight.Messaging;
    using System.Windows;

    public class MainViewModelWithCallBack : ViewModelBase
    {
        string _welcome = "Dialogs & MVVM";
        public string Welcome
        {
            get
            {
                return _welcome;
            }
            set
            {
                _welcome = value;
                RaisePropertyChanged("Welcome");
            }
        }

        ICommand _showDialogCommand;
        public ICommand ShowDialogCommand
        {
            get
            {
                if (_showDialogCommand == null)
                {
                    _showDialogCommand = new RelayCommand(
                        () =>
                        {
                            //var message = new NotificationMessage("Not so hard!");
                            var message = new DialogMessage("Are you sure", 
                                                                DialogMessageCallback)
                            {
                                Caption = "test",
                                Button = MessageBoxButton.YesNo

                            };

                            Messenger.Default.Send(message);
                        }
                        );
                }

                return _showDialogCommand;
            }
        }

        private void DialogMessageCallback(MessageBoxResult result)
        {
            if (result == MessageBoxResult.Yes)
            {
                Welcome = "Yes";
            }
            else
            {
                Welcome = "No";
            }
        }
    }
}